Ext.define('A5T.view.mywin.LoginForm', {
    extend: 'Ext.window.Window',

    requires: [
        'Ext.form.field.Text',
        'Ext.container.Container',
        'Ext.button.Button'
    ],

    height: 250,
    width: 400,
    bodyPadding: 10,
    title: '登陆',
    modal:true,
    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    id:'loginName',
                    fieldLabel: '帐号'
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    id:'loginPass',
                    fieldLabel: '密码'
                },
                {
                    xtype: 'container',
                    layout: {
                        type: 'hbox',
                        align: 'middle',
                        pack: 'center',
                        padding: 10
                    },
                    items: [
                        {
                            xtype: 'button',
                            margin: 10,
                            text: '登陆',
                            handler:function(button,e)
                            {
                                var panel = Ext.getCmp("top-region-container");
                                panel.removeAll();
                                var btn = new Ext.Button({
                                    text:'hi 你好！'
                                });
                                Ext.Ajax.request( {  
                                    url : '/a5t/index/login.json',  
                                    method : 'get',  
                                    params : {  
                                        loginName : Ext.getCmp('loginName').getValue(),  
                                        loginPass : Ext.getCmp('loginPass').getValue()  
                                    },  
                                    success : function(response, options) { 
                                        var res = Ext.decode(response.responseText);
                                        if(res.success){
                                            btn.setText("登陆成功");
                                        }else
                                        {
                                            btn.setText("登陆失败");
                                        }
                                        
                                        panel.add(btn);
                                        me.close();
                                    },  
                                    failure : function() {
                                        btn.setText("登陆失败");
                                        panel.add(btn);
                                        me.close();  
                                    }  
                                });
                                
                            }
                        },
                        {
                            xtype: 'button',
                            margin: 10,
                            text: '取消',
                            handler:function(button,e)
                            {
                                me.close();
                            }

                        }
                    ]
                }
            ]
        });

        me.callParent(arguments);
    }

});